package com.zhz.lib.project.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhz.lib.project.service.TypeService;
import com.zhz.lib.project.service.libnews.LibnewsService;
import com.zhz.lib.project.vo.libnews.LibnewsVO;

@Controller
@RequestMapping("/index.htm")
public final class IndexController {
    private static Logger  logger      = Logger.getLogger(IndexController.class);
    private static int     firstResult = 0;
    private static int     maxResults  = 4;
    @Autowired
    private LibnewsService libnewsService;
    @Autowired
    private TypeService    typeService;

    @RequestMapping(method = RequestMethod.GET)
    public String get(ModelMap model, HttpServletRequest request, HttpServletResponse response) {

        /////////////////////////////////////////////////////////////////
        //下面是列表信息
        List<LibnewsVO> tongzhiyuxiaoxiIndex = libnewsService.getLatestLibnewsBySortType(
            firstResult, maxResults, typeService.getTongzhiyuxiaoxiIndex());
        model.addAttribute("tongzhiyuxiaoxiIndex", tongzhiyuxiaoxiIndex);

        List<LibnewsVO> guanneixinxiIndex = libnewsService.getLatestLibnewsBySortType(firstResult,
            maxResults, typeService.getGuanneixinxiIndex());
        model.addAttribute("guanneixinxiIndex", guanneixinxiIndex);

        List<LibnewsVO> yewujiaoliuIndex = libnewsService.getLatestLibnewsBySortType(firstResult,
            maxResults, typeService.getYewujiaoliuIndex());
        model.addAttribute("yewujiaoliuIndex", yewujiaoliuIndex);

        List<LibnewsVO> xiazaikongjianIndex = libnewsService.getLatestLibnewsBySortType(
            firstResult, maxResults, typeService.getXiazaikongjianIndex());
        model.addAttribute("xiazaikongjianIndex", xiazaikongjianIndex);

        typeService.setToModelMap(model);
        return "index";
    }
}
